<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
    
    protected $connection = "default";

    public function up(): void
    {
        \support\Db::schema()->create('user',function (Blueprint $table){
            $table->increments('id');
            $table->string("username")->comment("用户名");
            $table->string("nickname")->nullable()->comment("昵称");
            $table->string("email")->nullable()->comment("邮箱地址");
            $table->string("mobile_phone")->nullable()->comment("手机号");
            $table->string("password")->comment("密码");
            $table->string("avatar")->comment("头像");
            $table->tinyInteger("state")->default(0)->comment("用户状态：-1禁止，0未激活，1正常");
            $table->tinyInteger("gender")->default(0)->comment("用户性别：-1女，0保密，1男");
            #$table->smallInteger("login_count")->default(0)->comment("用户登录次数");
            #$table->integer("last_login_ip")->default(0)->comment("最后登录id");
            #$table->integer("last_login_time")->default(0)->comment("最后登录id");
            $table->integer("register_time")->default(0)->comment("注册时间");
            $table->timestamp("invite_code")->comment("邀请码");
            $table->timestamps();
        });

        \support\Db::schema()->create('user_login_logs',function (Blueprint $table){
            $table->increments('id');
            $table->integer("user_id")->unsigned()->comment("用户id");
            $table->integer("login_ip")->comment("登录ip");
            $table->string("login_address")->comment("登录地址");
            $table->string("browser")->nullable()->comment("浏览器标识");
            $table->string("os")->nullable()->comment("操作系统");
            $table->integer("login_error")->default(0)->comment("错误代码");
            $table->integer("login_time")->unsigned()->comment("登录时间");
        });

        \support\Db::schema()->create('user_upload',function (Blueprint $table){
            $table->increments('id');

            $table->integer("user_id")->unsigned()->comment("用户id");
            $table->string("name")->comment("文件名");
            $table->string("type")->comment("文件类型");
            $table->integer("size")->default(0)->comment("文件大小");
            $table->string("path")->comment("保存路径");

            $table->timestamps();
        });
    }

    public function down(): void
    {
        \support\Db::schema()->dropIfExists('user');
        \support\Db::schema()->dropIfExists('user_login_logs');
        \support\Db::schema()->dropIfExists('user_upload');
    }
};